package cn.tang.crm.comm;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Utils {

	private static SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private static String ghostKnow = "Ghost Know";

	public static long timeMills(String timeStr){
		try {
			Date date=timeFormat.parse(timeStr);
			return date.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return 0;
	}
	
	public static String formatTime(long timeMills) {
		if (timeMills < 100)
			return "&nbsp;";
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(timeMills);
		return timeFormat.format(cal.getTime());
	}
	
	public static String payStatus(int payStatus) {
		if (payStatus == 1)
			return "not pay";
		else if (payStatus == 2)
			return "has pay";
		else
			return ghostKnow;
	}

	public static String clientClass(String clientClassID) {
//		if (cc == 1)
//			return "普通客户";
//		else if (cc == 2)
//			return "一般客户";
//		else if (cc == 3)
//			return "中上客户";
//		else if (cc == 4)
//			return "重要客户";
//		else
			return ghostKnow;
	}
	public static String clientType(String clientTypeID) {
//		if (ct == 1)
//			return "现场客户";
//		else if (ct == 2)
//			return "朋友介绍";
//		else if (ct == 3)
//			return "老客户";
//		else if (ct == 4)
//			return "展会";
//		else if (ct == 5)
//			return "网络,广告";
//		else
			return ghostKnow;
	}

	public static String roleType(String roleID) {
//		if (role == 1)
//			return "administrator";
//		else if (role == 2)
//			return "salesman";
//		else
			return ghostKnow;
	}

	public static String md5(String data) {
		byte[] source = data.getBytes();
		String s = null;
		char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
		try {
			java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
			md.update(source);
			byte tmp[] = md.digest();
			char str[] = new char[16 * 2];
			int k = 0;
			for (int i = 0; i < 16; i++) {

				byte byte0 = tmp[i];
				str[k++] = hexDigits[byte0 >>> 4 & 0xf];
				str[k++] = hexDigits[byte0 & 0xf];
			}
			s = new String(str);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return s;
	}
}
